﻿@using Aspire.Dashboard.Resources
@implements IDialogContentComponent
@inject IStringLocalizer<Dialogs> Loc

<FluentAnchor Style="margin-bottom: 5px;" Appearance="Appearance.Lightweight" Class="anchor-no-padding" Href="https://aka.ms/dotnet/aspire/dashboard">
    @Loc[nameof(Dialogs.HelpDialogGetHelpLinkText)]
</FluentAnchor>

<h5>@Loc[nameof(Dialogs.HelpDialogKeyboardShortcutsTitle)]</h5>

<FluentGrid Spacing="3">
    @foreach (var shortcutCategory in GetShortcutsByCategory())
    {
        <FluentGridItem xs="12" sm="6">
            <FluentStack Orientation="Orientation.Vertical" VerticalGap="3" style="border-radius: 0.375rem; border-style: solid; border-width: 1px; border-color: var(--neutral-layer-4); padding: 11px;">
                <h6 style="margin-bottom: 5px;">@shortcutCategory.Category</h6>
                <FluentStack Orientation="Orientation.Vertical" VerticalGap="6">
                    @foreach (var shortcut in shortcutCategory.Shortcuts)
                    {
                        <FluentStack Orientation="Orientation.Horizontal" width="100%">
                            @shortcut.Description
                            <FluentSpacer/>
                            <span>
                                @for (var i = 0; i < shortcut.Keys.Length; i++)
                                {
                                    <kbd style="margin-right: 3px;">@shortcut.Keys[i]</kbd>

                                    if (i < shortcut.Keys.Length - 1)
                                    {
                                        <span style="margin-right: 3px;">+</span>
                                    }
                                }
                            </span>
                        </FluentStack>
                    }
                </FluentStack>
            </FluentStack>
        </FluentGridItem>
    }
</FluentGrid>

@code {
    private List<KeyboardShortcutCategory> GetShortcutsByCategory() =>
    [
        new(Loc[nameof(Dialogs.HelpDialogCategoryPanels)],
        [
            new KeyboardShortcut(["+"], Loc[nameof(Dialogs.HelpDialogIncreasePanelSize)]),
            new KeyboardShortcut(["-"], Loc[nameof(Dialogs.HelpDialogDecreasePanelSize)]),
            new KeyboardShortcut(["shift", "r"], Loc[nameof(Dialogs.HelpDialogResetPanelSize)]),
            new KeyboardShortcut(["shift", "t"], Loc[nameof(Dialogs.HelpDialogTogglePanelOrientation)]),
            new KeyboardShortcut(["shift", "x"], Loc[nameof(Dialogs.HelpDialogTogglePanelOpen)]),
        ]),
        new(Loc[nameof(Dialogs.HelpDialogCategoryPageNavigation)],
        [
            new KeyboardShortcut(["r"], Loc[nameof(Dialogs.HelpDialogGoToResources)]),
            new KeyboardShortcut(["c"], Loc[nameof(Dialogs.HelpDialogGoToConsoleLogs)]),
            new KeyboardShortcut(["s"], Loc[nameof(Dialogs.HelpDialogGoToStructuredLogs)]),
            new KeyboardShortcut(["t"], Loc[nameof(Dialogs.HelpDialogGoToTraces)]),
            new KeyboardShortcut(["m"], Loc[nameof(Dialogs.HelpDialogGoToMetrics)]),
        ]),
        new(Loc[nameof(Dialogs.HelpDialogCategoryNavigation)],
        [
            new KeyboardShortcut(["?"], Loc[nameof(Dialogs.HelpDialogGoToHelp)]),
            new KeyboardShortcut(["shift", "s"], Loc[nameof(Dialogs.HelpDialogGoToSettings)])
        ])
    ];
}
